#include "Swarm.h"

Swarm::Swarm(){
	
}

Swarm::~Swarm(){
	delete player;
	delete cross;
	delete enemy;
}

void Swarm::Startup()
{
	Game::Startup();
	ID2D1Bitmap *tex = LoadImage(L"Images/topviewcharacter.png");
	player = new Player(tex);
	tex = LoadImage(L"Images/crosshair.png");
	cross = new Crosshair(tex);
	cross->Align(X_CENTER | Y_CENTER);
	player->Align(D2D1::Point2F(150.0F,180.0F));
	player->phyObj.phyWorld = &phyWorld;
	phyWorld.AddObject(player->phyObj);

	ID2D1Bitmap *orcTex = LoadImage(L"Images/sprites.png");
	enemy = new Orc(orcTex);

	ID2D1Bitmap *explosionTex = LoadImage(L"Images/explosion_30_128.png");
	explosion = new Explosion(explosionTex);
}

void Swarm::Render(){
	
	pRT->BeginDraw();
	pRT->Clear(D2DColor(Black));
		
		explosion->Render(pRT);
		enemy->Render(pRT);
		player->Render(pRT);
		cross->Render(pRT);

	pRT->EndDraw();
}

void Swarm::Update(long elapsedTime){
	explosion->Update(elapsedTime);
	player->Update(elapsedTime);
	enemy->Update(elapsedTime);
}

void Swarm::ProcessInput()
{
	double distX = (mouseCoord.width - player->phyObj.center.x);
	double distY = (player->phyObj.center.y - mouseCoord.height);
	player->Rotate(FLOAT(atan2(distX,distY)*(180 / pi)));
	cross->position.width = mouseCoord.width-15;
	cross->position.height = mouseCoord.height-15;

	if(keys['A'])
		player->Move(D2D1::SizeF(-1.0F,0.0F));

	if(keys['D'])
		player->Move(D2D1::SizeF(1.0F,0.0F));

	if(keys['W'])
		player->Move(D2D1::SizeF(0.0F,-1.0F));

	if(keys['S'])
		player->Move(D2D1::SizeF(0.0F,1.0F));
}
